package main

import (
	"encoding/json"
	"fmt"
)

func main() {
	parseStu()
	parseStu1()
	parseStu2()
}

type student struct {
	Name string
	Age  int
}

func parseStu() {
	m := make(map[string]*student)
	stus := []student{
		{
			Name: "zhou",
			Age:  24,
		}, {
			Name: "li",
			Age:  23,
		}, {
			Name: "wang",
			Age:  22,
		},
	}
	for _, stu := range stus {
		m[stu.Name] = &stu
	}

	by, _ := json.Marshal(m)
	fmt.Println(string(by))
}

func parseStu1() {
	m := make(map[string]*student)
	stus := []student{
		{
			Name: "zhou",
			Age:  24,
		}, {
			Name: "li",
			Age:  23,
		}, {
			Name: "wang",
			Age:  22,
		},
	}
	for _, stu := range stus {
		tmp := &stu
		m[stu.Name] = tmp
	}

	by, _ := json.Marshal(m)
	fmt.Println(string(by))
}

func parseStu2() {
	m := make(map[string]*student)
	stus := []student{
		{
			Name: "zhou",
			Age:  24,
		}, {
			Name: "li",
			Age:  23,
		}, {
			Name: "wang",
			Age:  22,
		},
	}
	for i := 0; i < len(stus); i++ {
		m[stus[i].Name] = &stus[i]
	}

	by, _ := json.Marshal(m)
	fmt.Println(string(by))
}
